package com.socialuni.jimei.utils.model;

import com.socialuni.api.model.RO.user.base.SocialUserRO;
import com.socialuni.jimei.model.DetailUserRO;
import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.model.DO.user.UserImgDO;
import com.socialuni.sdk.model.RO.UserImgRO;
import com.socialuni.sdk.utils.UserUtils;
import com.socialuni.sdk.utils.model.DO.UserImgDOUtils;
import com.socialuni.sdk.utils.model.RO.SocialUserROUtil;
import com.socialuni.sdk.utils.model.RO.UserImgROUtil;

import java.util.List;

public class UserDetailROUtil {
    //userDO转detailRO
    public static DetailUserRO userDOToDetailRO(UserDO userDO, Boolean isMine) {
        //user基础信息
        DetailUserRO userDetailVO = UserDetailROUtil.userDOTORO(userDO, isMine);
        userDetailVO = UserDetailROUtil.userDetailROSetImgs(userDetailVO, userDO);
        return userDetailVO;
    }

    //给detailRO设置imgs
    public static DetailUserRO userDetailROSetImgs(DetailUserRO userDetailVO, UserDO userDO) {
        //用户图片
//        List<UserImgRO> imgVOS = UserImgROUtil.getUesrImgVOs(Integer.parseInt(userDetailVO.getId()));

        //用户图片
        List<UserImgDO> imgDOS = UserImgDOUtils.getImgs(userDO.getId());
        List<UserImgRO> imgVOS = UserImgROUtil.userImgDOToVOS(imgDOS);
        userDetailVO.setImgs(imgVOS);

        return userDetailVO;
    }


    public static DetailUserRO getMineUserDetail() {
        UserDO userDO = UserUtils.getMineUser();
        assert userDO != null;
        return UserDetailROUtil.userDOToDetailRO(userDO, true);
    }

    public static DetailUserRO getMineUserDetail(UserDO userDO) {
        return UserDetailROUtil.userDOToDetailRO(userDO, true);
    }

    public static DetailUserRO getUserDetail(Integer userId) {
        UserDO userDO = UserUtils.get(userId);
        return UserDetailROUtil.userDOToDetailRO(userDO, false);
    }

    public static DetailUserRO getUserDetail(UserDO userDO) {
        return UserDetailROUtil.userDOToDetailRO(userDO, false);
    }

    //userRO转detailRO
    public static DetailUserRO userROToRO(SocialUserRO userDTO) {
        //user基础信息
        DetailUserRO user = new DetailUserRO();
        //user详情信息
//        user.setIsMine(userDTO.getIsMine());

        user.setId(userDTO.getId().toString());
        user.setNickname(userDTO.getNickname());
        user.setAvatar(userDTO.getAvatar());
        /*GenderTypeNumEnum genderTypeNumEnum = GenderTypeNumEnum.getEnumByValue(userDTO.getGender());
        if (genderTypeNumEnum == null) {
            throw new SocialException("错误的性别");
        }*/
//        user.setGender(userDTO.getGender());
//        user.setBirthday(userDTO.getBirthday());
        user.setAge(userDTO.getAge());
        user.setCity(userDTO.getCity());
//        user.setPhoneNum(userDTO.getPhoneNum());

        //未来可以考虑直接手机号也授权
        return user;
    }

    //这个应该只有内部会用，生成没有img的userdetailRo
    private static DetailUserRO userDOTORO(UserDO userDO, Boolean isMine) {
        SocialUserRO uniUserRO = SocialUserROUtil.userDOToRO(userDO, isMine);
        DetailUserRO UserDetailRO = UserDetailROUtil.userROToRO(uniUserRO);
        return UserDetailRO;
    }
}